<template>
  <div>
    <div class="allCount">
      <!-- <div class="allCount_head">近一月统计情况</div> -->
      <div class="box" v-for="(item ,index) in box" :style="{backgroundColor:item.color}" :key="index">
        <span>{{item.count}}</span>
        <div>{{item.name}}</div>
      </div>
    </div>
    <div class="main_bottom">
      <div
        ref="inventoryMgr"
        id="inventoryMgr"
        :style="{ width: '400px', height: '300px' }"
      ></div>
      <div
        ref="myChar"
        id="myChar"
        :style="{ width: '400px', height: '300px' }"
      ></div>
      <div
        ref="myChar1"
        id="myChar1"
        :style="{ width: '400px', height: '300px' }"
      ></div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      box: [
        {
          count: 100,
          name: '总订单',
          color: 'red'
        },
        {
          count: 100,
          name: '总租出',
          color: 'orange'
        },
        {
          count: 80,
          name: '总购入',
          color: 'green'
        },
        {
          count: 100000,
          name: '总库存',
          color: 'skyblue'
        },
        {
          count: 100000,
          name: '总收入',
          color: 'pink'
        },
        {
          count: 50,
          name: '新增客户',
          color: 'yellow'
        }
      ]
    }
  },
  methods: {
    drawLine () {
      // 基于准备好的dom，初始化echarts实例
      let inventoryMgr = this.$echarts.init(this.$refs.inventoryMgr)
      // 绘制图表
      inventoryMgr.setOption({
        color: ['#eaa'],
        title: { text: '近一月库存统计', left: 'center', top: 20 },
        grid: {
          left: '15%'
        },
        tooltip: {},
        xAxis: {
          data: ['租出数', '库余数', '已损坏数', '总购入数']
        },
        yAxis: {
          //   type: 'value',
          //   formatter: function (value, index) {
          //     if (value >= 10000 && value < 10000000) {
          //       value = value / 10000 + '万'
          //     } else if (value >= 10000000) {
          //       value = value / 10000000 + '千万'
          //     }
          //     return value
          //   }
        },
        series: [
          {
            name: '数量',
            type: 'bar',
            barWidth: '30%',
            data: [1000, 2000, 10000, 13000]
          }
        ]
      })
    },
    drawCake () {
      let myChar = this.$echarts.init(this.$refs.myChar)
      myChar.setOption({
        backgroundColor: '#2c343c',

        title: {
          text: '花卉种类占比',
          left: 'center',
          top: 20,
          textStyle: {
            color: '#ccc'
          }
        },

        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },

        visualMap: {
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0, 1]
          }
        },
        series: [
          {
            name: '花卉种类占比',
            type: 'pie',
            radius: '55%',
            center: ['50%', '50%'],
            data: [
              { value: 335, name: '草本花卉' },
              { value: 310, name: '球根花卉' },
              { value: 274, name: '多肉花卉' },
              { value: 235, name: '水生花卉' },
              { value: 400, name: '宿根花卉' }
            ].sort(function (a, b) {
              return a.value - b.value
            }),
            roseType: 'radius',
            label: {
              normal: {
                textStyle: {
                  color: 'rgba(255, 255, 255, 0.3)'
                }
              }
            },
            labelLine: {
              normal: {
                lineStyle: {
                  color: 'rgba(255, 255, 255, 0.3)'
                },
                smooth: 0.2,
                length: 10,
                length2: 20
              }
            },
            itemStyle: {
              normal: {
                color: '#c23531',
                shadowBlur: 200,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },

            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function (idx) {
              return Math.random() * 200
            }
          }
        ]
      })
    },
    drawZ () {
      let myChar1 = this.$echarts.init(this.$refs.myChar1)
      myChar1.setOption({
        title: {
          //   text: '堆叠区域图'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '邮件营销',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '联盟广告',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '视频广告',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: '直接访问',
            type: 'line',
            stack: '总量',
            areaStyle: { normal: {} },
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: '搜索引擎',
            type: 'line',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'top'
              }
            },
            areaStyle: { normal: {} },
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      })
    }
  },
  mounted () {
    this.drawLine()
    this.drawCake()
    this.drawZ()
  },
  components: {}
}
</script>

<style scoped>
@import "../../assets/css/reset.css";
@import "../../assets/css/main.css";
</style>
